import 'dart:io';

import 'package:flutter/material.dart';
import 'package:ileddemo/code/ui/base/BaseWidget.dart';
import 'package:lib_util/ToastUtil.dart';

import '../../../generated/l10n.dart';
import '../../ble/protocol/iledcolor/source/SourceManager.dart';
import '../../ble/protocol/iledcolor/source/SourceSendUtil.dart';
import '../../ble/protocol/iledcolor/source/gif/GifSourceBean.dart';
import '../../ble/protocol/iledcolor/source/partition/PartitionSourceBean.dart';
import '../base/SendAndSaveWidget.dart';
import '../base/TitleBarWidget.dart';

class EditGifPage extends StatefulWidget {
  final GifSourceBean sourceBean;

  const EditGifPage({super.key, required this.sourceBean});

  @override
  State<EditGifPage> createState() => _EditGifPageState();
}

class _EditGifPageState extends State<EditGifPage> {
  @override
  Widget build(BuildContext context) {
    return BaseWidget(
      child: Column(
        children: [
          TitleBarWidget(title: S.of(context).str_id_20),

          //素材展示
          SizedBox(
            height: 150,
            child: Image(
              image: FileImage(File(widget.sourceBean.imagePath)),
              fit: BoxFit.contain,
              filterQuality: FilterQuality.none,
            ),
          ),

          const SizedBox(height: 20),
          //发送和保存
          Padding(
            padding: const EdgeInsets.only(left: 10, right: 10),
            child: SendAndSaveWidget(
              sendText: S.of(context).str_id_4,
              saveText: S.of(context).str_id_5,
              sendTap: () => SourceSendUtil.instance.sendSource(
                widget.sourceBean.castPartitionSourceBean(),
              ),
              saveTap: () async {
                //保存
                SourceManager.instance.saveSource(widget.sourceBean);
                Navigator.of(context).pop();
                ToastUtil.showToast(S.of(context).str_id_17);
              },
            ),
          ),
        ],
      ),
    );
  }
}
